MutableList

interface MutableList<E> : List<E> , MutableCollection<E>

A generic ordered collection of elements that supports adding and removing elements.

Parameters

E

the type of elements contained in the list. The mutable list is invariant in its element type.

Functions

add
Link copied to clipboard
abstract override fun add(element: E): Boolean

Adds the specified element to the end of this list.

abstract fun add(index: Int, element: E)

Inserts an element into the list at the specified index.

addAll
Link copied to clipboard
abstract override fun addAll(elements: Collection<E>): Boolean

Adds all of the elements of the specified collection to the end of this list.

abstract fun addAll(index: Int, elements: Collection<E>): Boolean

Inserts all of the elements of the specified collection elements into this list at the specified index.

clear
Link copied to clipboard
abstract override fun clear()

Removes all elements from this collection.

contains
Link copied to clipboard
abstract operator override fun contains(element: E): Boolean

Checks if the specified element is contained in this collection.

containsAll
Link copied to clipboard
abstract override fun containsAll(elements: Collection<E>): Boolean

Checks if all elements in the specified collection are contained in this collection.

get
Link copied to clipboard
abstract operator fun get(index: Int): E

Returns the element at the specified index in the list.

indexOf
Link copied to clipboard
abstract fun indexOf(element: E): Int

Returns the index of the first occurrence of the specified element in the list, or -1 if the specified element is not contained in the list.

isEmpty
Link copied to clipboard
abstract override fun isEmpty(): Boolean

Returns true if the collection is empty (contains no elements), false otherwise.

iterator
Link copied to clipboard
abstract operator override fun iterator(): Iterator<E>

Returns an iterator over the elements of this object.

lastIndexOf
Link copied to clipboard
abstract fun lastIndexOf(element: E): Int

Returns the index of the last occurrence of the specified element in the list, or -1 if the specified element is not contained in the list.

listIterator
Link copied to clipboard
abstract override fun listIterator(): MutableListIterator<E>

Returns a list iterator over the elements in this list (in proper sequence).

abstract override fun listIterator(index: Int): MutableListIterator<E>

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified index.

remove
Link copied to clipboard
abstract override fun remove(element: E): Boolean

Removes a single instance of the specified element from this collection, if it is present.

removeAll
Link copied to clipboard
abstract override fun removeAll(elements: Collection<E>): Boolean

Removes all of this collection's elements that are also contained in the specified collection.

removeAt
Link copied to clipboard
abstract fun removeAt(index: Int): E

Removes an element at the specified index from the list.

retainAll
Link copied to clipboard
abstract override fun retainAll(elements: Collection<E>): Boolean

Retains only the elements in this collection that are contained in the specified collection.

set
Link copied to clipboard
abstract operator fun set(index: Int, element: E): E

Replaces the element at the specified position in this list with the specified element.

subList
Link copied to clipboard
abstract override fun subList(fromIndex: Int, toIndex: Int): MutableList<E>

Returns a view of the portion of this list between the specified fromIndex (inclusive) and toIndex (exclusive). The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa.

Properties

size
Link copied to clipboard
abstract override val size: Int

Returns the size of the collection.

Inheritors

AbstractMutableList
Link copied to clipboard
ArrayList
Link copied to clipboard

Extensions

asReversed
Link copied to clipboard
@JvmName(name = "asReversedMutable")
fun <T> MutableList<T>.asReversed(): MutableList<T>

Returns a reversed mutable view of the original mutable List. All changes made in the original list will be reflected in the reversed one and vice versa.

fill
Link copied to clipboard
expect fun <T> MutableList<T>.fill(value: T)
actual inline fun <T> MutableList<T>.fill(value: T)

Fills the list with the provided value.

actual fun <T> MutableList<T>.fill(value: T)

Fills the list with the provided value.

actual fun <T> MutableList<T>.fill(value: T)

Fills the list with the provided value.

remove
Link copied to clipboard
inline fun <T> MutableList<T>.remove(index: Int): T

Removes the element at the specified index from this list. In Kotlin one should use the MutableList.removeAt function instead.

removeAll
Link copied to clipboard
fun <T> MutableList<T>.removeAll(predicate: (T) -> Boolean): Boolean

Removes all elements from this MutableList that match the given predicate.

removeFirst
Link copied to clipboard
fun <T> MutableList<T>.removeFirst(): T

Removes the first element from this mutable list and returns that removed element, or throws NoSuchElementException if this list is empty.

removeFirstOrNull
Link copied to clipboard
fun <T> MutableList<T>.removeFirstOrNull(): T?

Removes the first element from this mutable list and returns that removed element, or returns null if this list is empty.

removeLast
Link copied to clipboard
fun <T> MutableList<T>.removeLast(): T

Removes the last element from this mutable list and returns that removed element, or throws NoSuchElementException if this list is empty.

removeLastOrNull
Link copied to clipboard
fun <T> MutableList<T>.removeLastOrNull(): T?

Removes the last element from this mutable list and returns that removed element, or returns null if this list is empty.

replaceAll
Link copied to clipboard
fun <T> MutableList<T>.replaceAll(transformation: (T) -> T)

Replaces each element in the list with a result of a transformation specified.

retainAll
Link copied to clipboard
fun <T> MutableList<T>.retainAll(predicate: (T) -> Boolean): Boolean

Retains only elements of this MutableList that match the given predicate.

reverse
Link copied to clipboard
expect fun <T> MutableList<T>.reverse()

Reverses elements in the list in-place.

actual fun <T> MutableList<T>.reverse()

Reverses elements in the list in-place.

actual fun <T> MutableList<T>.reverse()

Reverses elements in the list in-place.

actual fun <T> MutableList<T>.reverse()

Reverses elements in the list in-place.

shuffle
Link copied to clipboard
fun <T> MutableList<T>.shuffle(random: Random)

Randomly shuffles elements in this list in-place using the specified random instance as the source of randomness.

expect fun <T> MutableList<T>.shuffle()
inline fun <T> MutableList<T>.shuffle(random: Random)

Randomly shuffles elements in this mutable list using the specified random instance as the source of randomness.

actual inline fun <T> MutableList<T>.shuffle()

Randomly shuffles elements in this mutable list.

actual fun <T> MutableList<T>.shuffle()

Randomly shuffles elements in this list.

actual fun <T> MutableList<T>.shuffle()

Randomly shuffles elements in this list.

sort
Link copied to clipboard
expect fun <T : Comparable<T>> MutableList<T>.sort()
inline fun <T> MutableList<T>.sort(comparator: Comparator<in T>)
inline fun <T> MutableList<T>.sort(comparison: (T, T) -> Int)

actual fun <T : Comparable<T>> MutableList<T>.sort()

Sorts elements in the list in-place according to their natural sort order.

actual fun <T : Comparable<T>> MutableList<T>.sort()

Sorts elements in the list in-place according to their natural sort order.

actual fun <T : Comparable<T>> MutableList<T>.sort()

Sorts elements in the list in-place according to their natural sort order.

sortBy
Link copied to clipboard
inline fun <T, R : Comparable<R>> MutableList<T>.sortBy(crossinline selector: (T) -> R?)

Sorts elements in the list in-place according to natural sort order of the value returned by specified selector function.

sortByDescending
Link copied to clipboard
inline fun <T, R : Comparable<R>> MutableList<T>.sortByDescending(crossinline selector: (T) -> R?)

Sorts elements in the list in-place descending according to natural sort order of the value returned by specified selector function.

sortDescending
Link copied to clipboard
fun <T : Comparable<T>> MutableList<T>.sortDescending()

Sorts elements in the list in-place descending according to their natural sort order.

sortWith
Link copied to clipboard
expect fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>)
actual fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>)

Sorts elements in the list in-place according to the order specified with comparator.

actual fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>)

Sorts elements in the list in-place according to the order specified with comparator.